#ifndef _VFX_WATER_H_
#define _VFX_WATER_H_

#include <string>
#include "graphics/graphics.h"
#include "graphics/image_cache.h"
#include "math/vec2.h"
#include "ui/ui_sprite.h"

namespace vfx
{
class		VFXWater
{
public:
	VFXWater(const math::Vec2& Offset, const math::Vec2& Size);
	~VFXWater();

	void			Create(int Width, int Height, const std::string& Texture);
	virtual void	Tick(float dt, const math::Vec2& Offset);
	virtual void	Render(const math::Vec2& Offset, float Scale);
	virtual void	RenderDebug(const math::Vec2& Offset, float Scale);

	void			AddWave(const math::Vec2& Pos, float Depth);
	void			AddWaveArea(const math::Vec2& From, const math::Vec2& To, float Depth);

	void			ClearGround();
	void			AddGroundSphere(const math::Vec2& Pos, float Rad, bool SetVak);

	virtual void	RenderUnderWater(const math::Vec2& Offset, float Scale);
	bool			StartCache(const math::Vec2& Offset, float Scale);
	void			FinishCache();
	const std::string&	 GetFile() const { return m_BaseTexture.GetFilename(); };
	float			GetBaseColor() const { return m_BaseColor; };
	void			SetBaseColor(float f) { m_BaseColor = f; };
	void			SetBackground(const std::string& File);
	void			RenderUI();
protected:
	inline int		GetIndex(int x, int y);
	inline bool		IsGround(int x, int y) const;
	void	SetImpulse(int	x, int y, int Height = 1000);
	
	void			RenderDualLayer(const math::Vec2& Offset, int minx, int miny, int maxx, int maxy);
	void			BuildIndices();
	void			GetExtents(int& minx, int& miny, int& maxx, int& maxy, const math::Vec2& Offset);
	void			GetExtents(int& minx, int& miny, int& maxx, int& maxy, const math::Vec2& From, const math::Vec2& To);

	int		m_TexW, m_TexH;
	int		m_Width, m_Height;
	int*	m_GridA;
	int*	m_TempA;

	float	m_Simulate;

	ui::UISprite	m_BaseTexture;
	bool*			m_GroundA;

	math::Vec2		m_Offset, m_Size, m_BlockSize, m_UVScale;

	// drawing stuff
	unsigned short*			m_IndexA;
	Graphics::Vertex2D*		m_VertexA;
	int						m_RenderW, m_RenderH;
	int						m_IndexC;

	//drawing stuff with under-water image
	ImageCache*				m_pUnderwater;
	int						m_UnderwaterC;	// number of underwater objects in the current texture
	float					m_BaseColor;

};

} // namespace horde

#endif // _VFX_WATER_H_